#include "client.h"

client::client() {
    clientRunning = true;
    SDL_ShowCursor(SDL_DISABLE);
//    SDL_WM_GrabInput(SDL_GRAB_ON);
}

void client::updateClient() {
    retrieveUserInput();

    if(currentFrame() % 60 == 0) {
        updatePosition();
    }

    //Physics
    cout << "Frame: " << currentFrame() << endl;
    if(!checkBelow(currentPosition(), currentMap(), currentMapSize())) {
        updateVel(0.00, fallingObject(currentVelocity().dy), 0.00);
    } else {
        updateVel(0.00, 0.00, 0.00);
    }

    handleKeyInput();
	handleMouseInput();

    drawScene();
    if(currentFrame() % 2 == 0) {SDL_WarpMouse(400, 300);}

}

bool client::isRunning() {
    return clientRunning;
}

void client::handleKeyInput()
{
	if(currentStates()[SDLK_ESCAPE]) clientRunning = false;

	if(currentStates()[SDLK_w])	moveForward();
    if(currentStates()[SDLK_s])	moveBackward();
    if(currentStates()[SDLK_a]) strafeLeft();
    if(currentStates()[SDLK_d])	strafeRight();
    if(currentStates()[SDLK_r])	moveUp();
    if(currentStates()[SDLK_f])	moveDown(0.01);
}

void client::handleMouseInput()
{
	if(currentMouse().x < 390) {
        rotateLeft(currentMouse().x - 400);
    }
    if(currentMouse().x > 410) {
        rotateRight(currentMouse().x - 400);
    }
    if(currentMouse().y < 290) {
        lookUp(currentMouse().y - 300);
    }
    if(currentMouse().y > 310) {
        lookDown(currentMouse().y - 300);
    }
}